package com.gao.mq.handler.factory;

import com.gao.mq.constant.Constants;
import com.gao.mq.handler.IMessageHandler;
import com.gao.mq.handler.impl.EmailHandler;
import com.gao.mq.handler.impl.SmsHandler;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 消息处理配置类
 */
public class MessageHandlerConfig {

    protected static Map<Integer, IMessageHandler> handlerMap = new ConcurrentHashMap<>();

    @Autowired
    private SmsHandler smsHandler;

    @Autowired
    private EmailHandler emailHandler;

    /**
     * 初始化消息类型与Handler的映射关系
     */
    @PostConstruct
    public void init() {
        handlerMap.put(Constants.MessageType.SMS.getCode(), smsHandler);
        handlerMap.put(Constants.MessageType.EMAIL.getCode(), emailHandler);
    }
}
